// Copyright (c) 2007 Alistair Jones
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.codegen;

import static org.hypirinha.html.codegen.CodegenUtil.commaSeparate;

import java.util.List;
import java.util.ArrayList;

public class GeneratedClass extends CompilationUnit {

    private String superClass;
    protected List<String> implementedInterfaces = new ArrayList<String>();

    public GeneratedClass(String packageName, String className) {
        super(packageName, className);
    }

    protected String startDeclaration() {
        return "public class " + className + formatBaseClass() + formatInterfaces() + " {";
    }

    private String formatBaseClass() {
        return superClass == null ? "" : " extends " + superClass;
    }

    private String formatInterfaces() {
        if (implementedInterfaces.isEmpty()) {
            return "";
        }
        return " implements " + commaSeparate(implementedInterfaces);
    }

    public void addInterface(String interfaceName) {
        implementedInterfaces.add(interfaceName);
    }

    public void setSuperClass(String superClass) {
        this.superClass = superClass;
    }

    public List<String> getImplementedInterfaces() {
        return implementedInterfaces;
    }
}
